home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cujaug93.zip / 1108099A < prev    next >
Text File  |  1993-06-08  |  8KB  |  253 lines

  1.        /*********************************************
  2.        *
  3.        *   file d:\cips\mainsk.c
  4.        *
  5.        *   Functions: This file contains
  6.        *      main
  7.        *
  8.        *   Purpose:
  9.        *      This file contains the main calling
  10.        *      routine that calls the erosion, dilation,
  11.        *      outline, and skeleton functions.
  12.        *
  13.        *   External Calls:
  14.        *      gin.c - get_image_name
  15.        *      numcvrt.c - get_integer
  16.        *                  int_convert
  17.        *      tiff.c - read_tiff_header
  18.        *      ed.c - erosion
  19.        *             dilation
  20.        *             mask_erosion
  21.        *             mask_dilation
  22.        *             interior_outline
  23.        *             exterior_outline
  24.        *             opening
  25.        *             closing
  26.        *      skeleton.c - thinning
  27.        *                   skeleton
  28.        *                   dilate_not_join
  29.        *                   special_opening
  30.        *                   special_closing
  31.        *                   edm
  32.        *                   mat
  33.        *
  34.        *   Modifications:
  35.        *      7 March 1993 - created
  36.        *
  37.        ***********************************************/
  38.  
  39. #include "cips.h"
  40.  
  41.  
  42.  
  43. short the_image[ROWS][COLS];
  44. short out_image[ROWS][COLS];
  45.  
  46. main(argc, argv)
  47.    int argc;
  48.    char *argv[];
  49. {
  50.  
  51.    char     name[80], name2[80], name3[80], type[80];
  52.    int      count, i, j,
  53.             il, ie, ll, le,
  54.             length, lw, mask_type, number,
  55.             threshold, width;
  56.    short    value;
  57.    struct   tiff_header_struct image_header;
  58.  
  59.    my_clear_text_screen();
  60.  
  61.        /*********************************************
  62.        *
  63.        *   Interpret the command line parameters.
  64.        *
  65.        **********************************************/
  66.  
  67.    if(argc < 5){
  68.     printf(
  69.     "\n\nNot enough parameters:"
  70.      "\n"
  71.      "\n usage: mainsk in-file out-file type value"
  72.      " [threshold-or-mask-type] [number]"
  73.      "\n"
  74.      "\n recall type: EROsion DILation Mask-ERosion"
  75.      "\n              Mask_DIlation INTerior-outline"
  76.      "\n              EXTerior-outline THInning"
  77.      "\n              Dilate-Not-Join OPEning"
  78.      "\n              CLOsing SPecial-Opening"
  79.      "\n              SPecial-Closing"
  80.      "\n              Euclidean-Distance-Measure"
  81.      "\n              Medial-Axis-Transform"
  82.      "\n"
  83.      "\n              [number] needed for opening"
  84.      "\n              and closing"
  85.      "\n");
  86.     exit(0);
  87.    }
  88.  
  89.    strcpy(name,     argv[1]);
  90.    strcpy(name2,    argv[2]);
  91.    strcpy(type,     argv[3]);
  92.    value     = atoi(argv[4]);
  93.    threshold = atoi(argv[5]);
  94.    mask_type = atoi(argv[5]);
  95.    number    = atoi(argv[6]);
  96.  
  97.    il = 1;
  98.    ie = 1;
  99.    ll = ROWS+1;
  100.    le = COLS+1;
  101.  
  102.        /*********************************************
  103.        *
  104.        *   Read the input image header and setup
  105.        *   the looping counters.
  106.        *
  107.        **********************************************/
  108.  
  109.    read_tiff_header(name, &image_header);
  110.  
  111.    length = (90 + image_header.image_length)/ROWS;
  112.    width  = (90 + image_header.image_width)/COLS;
  113.    count  = 1;
  114.    lw     = length*width;
  115.    printf("\nlength=%d  width=%d", length, width);
  116.  
  117.        /*********************************************
  118.        *
  119.        *   Loop over the input images and
  120.        *   apply the desired function.
  121.        *
  122.        **********************************************/
  123.  
  124.    for(i=0; i<length; i++){
  125.       for(j=0; j<width; j++){
  126.          printf("\nrunning %d of %d", count, lw);
  127.          count++;
  128.  
  129.             /* thinning */
  130.          if(strncmp("thi", type, 3) == 0){
  131.             thinning(name, name2, the_image, out_image,
  132.                      il+i*ROWS, ie+j*COLS,
  133.                      ll+i*ROWS, le+j*COLS,
  134.                      value, threshold, 0);
  135.          }  /* ends thinning operation */
  136.  
  137.             /* dilate-not-join */
  138.          if(strncmp("dnj", type, 3) == 0){
  139.             dilate_not_join(name, name2, 
  140.                             the_image, out_image,
  141.                             il+i*ROWS, ie+j*COLS,
  142.                             ll+i*ROWS, le+j*COLS,
  143.                             value, threshold);
  144.          }  /* ends dilate_not_join operation */
  145.  
  146.             /* erosion */
  147.          if(strncmp("ero", type, 3) == 0){
  148.             erosion(name, name2, the_image, out_image,
  149.                     il+i*ROWS, ie+j*COLS,
  150.                     ll+i*ROWS, le+j*COLS,
  151.                     value, threshold);
  152.          }  /* ends erosion operation */
  153.  
  154.             /* dilation */
  155.          if(strncmp("dil", type, 3) == 0){
  156.             dilation(name, name2, the_image, out_image,
  157.                      il+i*ROWS, ie+j*COLS,
  158.                      ll+i*ROWS, le+j*COLS,
  159.                      value, threshold);
  160.          }  /* ends dilation operation */
  161.  
  162.             /* mask_erosion */
  163.          if(strncmp("mer", type, 3) == 0){
  164.             mask_erosion(name, name2, the_image,
  165.                          out_image, il+i*ROWS,
  166.                          ie+j*COLS, ll+i*ROWS,
  167.                          le+j*COLS, value, mask_type);
  168.          }  /* ends mask_erosion operation */
  169.  
  170.             /* mask_dilation */
  171.          if(strncmp("mdi", type, 3) == 0){
  172.             mask_dilation(name, name2, the_image,
  173.                           out_image, il+i*ROWS,
  174.                           ie+j*COLS, ll+i*ROWS,
  175.                           le+j*COLS, value, mask_type);
  176.          }  /* ends mask_dilation operation */
  177.  
  178.             /* interior_outline */
  179.          if(strncmp("int", type, 3) == 0){
  180.             interior_outline(name, name2, the_image,
  181.                              out_image, il+i*ROWS,
  182.                              ie+j*COLS, ll+i*ROWS,
  183.                              le+j*COLS, value,
  184.                              mask_type);
  185.          }  /* ends interior_outline operation */
  186.  
  187.             /* exterior_outline */
  188.          if(strncmp("ext", type, 3) == 0){
  189.             exterior_outline(name, name2, the_image,
  190.                              out_image, il+i*ROWS,
  191.                              ie+j*COLS, ll+i*ROWS,
  192.                              le+j*COLS, value,
  193.                              mask_type);
  194.          }  /* ends exterior_outline operation */
  195.  
  196.             /* opening */
  197.          if(strncmp("ope", type, 3) == 0){
  198.             opening(name, name2, the_image,
  199.                     out_image, il+i*ROWS,
  200.                     ie+j*COLS, ll+i*ROWS,
  201.                     le+j*COLS, value,
  202.                     mask_type, number);
  203.          }  /* ends opening operation */
  204.  
  205.             /* closing */
  206.          if(strncmp("clo", type, 3) == 0){
  207.             closing(name, name2, the_image,
  208.                     out_image, il+i*ROWS,
  209.                     ie+j*COLS, ll+i*ROWS,
  210.                     le+j*COLS, value,
  211.                     mask_type, number);
  212.          }  /* ends closing operation */
  213.  
  214.             /* special opening */
  215.          if(strncmp("spo", type, 3) == 0){
  216.             special_opening(name, name2, the_image,
  217.                             out_image, il+i*ROWS,
  218.                             ie+j*COLS, ll+i*ROWS,
  219.                             le+j*COLS, value,
  220.                             threshold, number);
  221.          }  /* ends special opening operation */
  222.  
  223.             /* special closing */
  224.          if(strncmp("spc", type, 3) == 0){
  225.             special_closing(name, name2, the_image,
  226.                             out_image, il+i*ROWS,
  227.                             ie+j*COLS, ll+i*ROWS,
  228.                             le+j*COLS, value,
  229.                             mask_type, number);
  230.          }  /* ends special closing operation */
  231.  
  232.             /* Euclidean Distance Measure */
  233.          if(strncmp("edm", type, 3) == 0){
  234.             edm(name, name2, the_image,
  235.                 out_image, il+i*ROWS,
  236.                 ie+j*COLS, ll+i*ROWS,
  237.                 le+j*COLS, value);
  238.          }  /* ends Euclidean distance mesaure */
  239.  
  240.             /* medial axis transform */
  241.          if(strncmp("mat", type, 3) == 0){
  242.             mat(name, name2, the_image,
  243.                 out_image, il+i*ROWS,
  244.                 ie+j*COLS, ll+i*ROWS,
  245.                 le+j*COLS, value);
  246.          }  /* ends medial axis transform operation */
  247.  
  248.       }  /* ends loop over j */
  249.    }  /* ends loop over i */
  250. }  /* ends main  */
  251.  
  252.  
  253.